import { axios } from '@choerodon/master';
import { useEffect, useState } from 'react';

const useGetPersonalToken = (projectId:string) => {
  const [personalToken, setPersonalToken] = useState('');

  useEffect(() => {
    async function asyncFunc() {
      const res = await axios.get(`/devops/v1/projects/${projectId}/pipelines/personal_token`);
      setPersonalToken(res);
    }
    asyncFunc();
  }, []);

  return [personalToken, setPersonalToken] as const;
};

export default useGetPersonalToken;
